package cn.yusei.teamTribe.dao.team;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import cn.yusei.teamTribe.dao.team.po.TeamAlbumPO;

@Mapper
public  interface TeamAlbumDAO {

	String PHOTO_ALBUM_TABLE = " e_album ";
	String INSERT_FIELDS = " (type, team_id, name, cover, description) ";
	String SELECT_FIELDS = " id, type, team_id, name, cover, description, create_time ";
	
	@Insert({"insert into", PHOTO_ALBUM_TABLE, INSERT_FIELDS, "values (#{type}, #{teamId}, #{name}, #{cover}, #{description})"})
	void insert(TeamAlbumPO taPO);
	
	@Select({"select exists (select * from", PHOTO_ALBUM_TABLE, "where id = #{id} and team_id = #{teamId})"})
	boolean exists(@Param("id") int id, @Param("teamId") int teamId);
	
	@Select({"select exists (select * from", PHOTO_ALBUM_TABLE, "where team_id = #{teamId} and name = #{name})"})
	boolean existsName(@Param("teamId") int teamId, @Param("name") String name);
	
	@Select({"select id from", PHOTO_ALBUM_TABLE, "where team_id = #{teamId}"})
	int[] selectByTeamId(@Param("teamId") int teamId);
	
	@Select({"select", SELECT_FIELDS, "from", PHOTO_ALBUM_TABLE, "where id = #{id}"})
	TeamAlbumPO selectById(@Param("id") int id);
	
	@Delete({"delete from", PHOTO_ALBUM_TABLE, "where id = #{id} and team_id = #{teamId}"})
	void delete(@Param("id") int id, @Param("teamId") int teamId);
	
	@Update({"update", PHOTO_ALBUM_TABLE, "set name = #{name}, description = #{description}, cover = #{cover} where id = #{id}"})
	void update(TeamAlbumPO taPO);
	
	@Select({"select last_insert_id()"})
	int selectLastInsertId();
	
}
